/**
 * Copyright (C) 2011-2012 GreenSoft S.A.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *        http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ar.com.greensoft.neosystem.common;

import ar.com.greensoft.neosystem.crm.web.beans.NavigationConstants;

/**
 * 
 * @author Jorge E. Villaverde
 * @date 22/01/2012
 * @version 1.0.0
 */
public class CrudMenu extends CompositeMenuItem implements NavigationConstants {
	private final String entityName;
	private final String entityPath;
	
	public CrudMenu(String entityName, String entityPath) {
		super(buildEntityLabel(entityName), buildEntityDefaultAction(entityPath));

		this.entityName = entityName;
		this.entityPath = entityPath;
		
		addMenuItem(new SimpleMenuItem("Nueva " + entityName, buildEntityAction(entityPath, CREATE_ACTION)));
	}

	private static String buildEntityDefaultAction(String entityPath) {
		return buildEntityAction(entityPath, INDEX_ACTION);
	}

	private static String buildEntityAction(String entityPath, String action) {
		StringBuilder builder = new StringBuilder();
		
		builder.append(entityPath);
		if(!entityPath.endsWith(PATH_SEPARATOR))
			builder.append(PATH_SEPARATOR);
		
		builder.append(action);
		builder.append(FILE_EXT);
		
		return builder.toString();
	}
	
	private static String buildEntityLabel(String entityName) {
		return entityName + "s";
	}

	public String getEntityName() {
		return entityName;
	}

	public String getEntityPath() {
		return entityPath;
	}

}
